package com.wangtao.firstapp.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;

import com.wangtao.firstapp.R;
import com.wangtao.firstapp.adapters.HomeVPAdapter;
import com.wangtao.firstapp.fragments.communityfragment.MyFollowsArticlesFragment;
import com.wangtao.firstapp.fragments.communityfragment.MyFollowsShowFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 文章列表下 关注动态 按钮的二级页面
 * <p/>
 * Created by lanouhn on 16/8/31.
 */
public class MyFollowsActivity extends AppCompatActivity {
    private HomeVPAdapter homeVPAdapter;
    private ViewPager viewpager_myfollows;
    private TabLayout tablayout_myfollows;
    private ImageButton ib_myfollows;
    //private SwipeRefreshLayout swiperefreshlayout_myfollows;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myfollows);
        viewpager_myfollows = (ViewPager) findViewById(R.id.viewpager_myfollows);
        tablayout_myfollows = (TabLayout) findViewById(R.id.tablayout_myfollows);
        ib_myfollows = (ImageButton) findViewById(R.id.ib_myfollows);
        // swiperefreshlayout_myfollows = (SwipeRefreshLayout) findViewById(R.id.swiperefreshlayout_myfollows);
        initData();
        initEvent();
        //SwipeToRefresh();
    }

    private void initData() {
        List<String> tabnames = new ArrayList<>();
        ArrayList<Fragment> fragments = new ArrayList<>();
        MyFollowsArticlesFragment followsFragment = new MyFollowsArticlesFragment();
        MyFollowsShowFragment showFragment = new MyFollowsShowFragment();
        tabnames.add("文章");
        tabnames.add("晒单");
        fragments.add(followsFragment);
        fragments.add(showFragment);
        homeVPAdapter = new HomeVPAdapter(getSupportFragmentManager(), tabnames, fragments);
        viewpager_myfollows.setAdapter(homeVPAdapter);
        tablayout_myfollows.setupWithViewPager(viewpager_myfollows);
    }

    private void initEvent() {
        // 页面左上角返回按钮，点击销毁当前Activity
        ib_myfollows.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    // 下拉刷新
//    private void SwipeToRefresh() {
//        swiperefreshlayout_myfollows.setColorSchemeColors(Color.CYAN, Color.BLUE, Color.GREEN, Color.YELLOW);
//        swiperefreshlayout_myfollows.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
//            @Override
//            public void onRefresh() {
//                swiperefreshlayout_myfollows.setRefreshing(true);
//                (new Handler()).postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        swiperefreshlayout_myfollows.setRefreshing(false);
//
//                        homeVPAdapter.notifyDataSetChanged();
//                    }
//                }, 3000);
//            }
//        });
//    }

}
